package com.lj.job.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lj.common_web.annotation.ResponseResultVo;
import com.lj.job.param.JobPageParam;
import com.lj.job.param.JobSaveParam;
import com.lj.job.param.JobUpdateParam;
import com.lj.job.result.JobInfoResult;
import com.lj.job.result.JobPageResult;
import com.lj.job.service.JobService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 定时任务 前端控制器
 * </p>
 *
 * @author luojing
 * @since 2025-03-20 15:23:28
 */
@RestController
@RequestMapping("/job")
@ResponseResultVo
@Tag(name = "定时任务 管理")
public class JobController {

    @Resource
    private JobService jobService;

    @GetMapping("/page")
    @SaCheckPermission("job:job:list")
    @Operation(summary = "定时任务 分页查询")
    public IPage<JobPageResult> page(@ParameterObject JobPageParam param) {
        return jobService.page(param);
    }

    @GetMapping("/info/{id}")
    @SaCheckPermission("job:job:info")
    @Operation(summary = "定时任务 信息")
    public JobInfoResult info(@PathVariable("id") @Parameter(name = "id", description = "定时任务 id") Long id) {
        return jobService.info(id);
    }

    @PostMapping("/save")
    @SaCheckPermission("job:job:save")
    @Operation(summary = "定时任务 新增")
    public void save(@RequestBody @Validated JobSaveParam param) {
        jobService.save(param);
    }

    @PostMapping("/update")
    @SaCheckPermission("job:job:update")
    @Operation(summary = "定时任务 更新")
    public void update(@RequestBody @Validated JobUpdateParam param) {
        jobService.update(param);
    }

    @PostMapping("/delete")
    @SaCheckPermission("job:job:delete")
    @Operation(summary = "定时任务 删除")
    public void delete(@RequestBody List<Long> ids) {
        jobService.delete(ids);
    }

    @PostMapping("/run")
    @SaCheckPermission("job:job:run")
    @Operation(summary = "立即执行任务")
    public void run(@RequestBody List<Long> ids) {
        jobService.run(ids);
    }

    @PostMapping("/pause")
    @SaCheckPermission("job:job:pause")
    @Operation(summary = "暂停定时任务")
    public void pause(@RequestBody List<Long> ids) {
        jobService.pause(ids);
    }

    @PostMapping("/resume")
    @SaCheckPermission("job:job:resume")
    @Operation(summary = "恢复定时任务")
    public void resume(@RequestBody List<Long> ids) {
        jobService.resume(ids);
    }

}

